const joi = require("joi");

// 定义规则
const id = joi.number().integer().min(1).required();
const username = joi.string().min(1).max(10).required();
const password = joi
    .string()
    .pattern(/^[\S]{3,12}$/)
    .required();
const nickname = joi.string().required();
const email = joi.string().email().required();
const headPic = joi.string().dataUri().required();
// 登录和注册校验
exports.reg_login_schema = {
    body: {
        username,
        password,
    },
};

// 修改用户信息校验
exports.update_userinfo_schema = {
    body: {
        id,
        nickname,
        email,
    },
};
// 修改密码校验
exports.update_password_schema = {
    body: {
        oldPassword: password,
        // 旧密码与新密码不能一致，且校验规则与password一致
        newPassword: joi.not(joi.ref("oldPassword")).concat(password),
    },
};

// 头像格式校验base64
exports.update_headpic_schema = {
    body: {
        headPic,
    },
};